<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- BEGIN GLOBAL MANDATORY STYLES -->

    <!-- BEGIN GLOBAL MANDATORY STYLES -->
    <#include "../inc/list.ftl"/>
    <@list/>
</head>
<body >
<div class="panel panel-default">
    <div class="panel-body">
        <div class="row">
            <div class="col-lg-12">
                <form id="form" >
                    <div class="form-group">
                        <label>ID</label>
                        <input id="userid"  name="userid"  class="form-control">
                    </div>
                    <div class="form-group">
                        <label>用户名</label>
                        <input id="username"  name="usernmae"  class="form-control">
                    </div>
                    <div class="form-group">
                        <label>权限</label>
                        <select id="role"  name="role"  class="form-control" >
                        </select>
                    </div>
                    <div align="right">
                        <button id="btn-submit"  type="button"  class="btn btn-default" >提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- /.panel-body -->
</div>
<!-- /.panel -->
<script>
    $(document).ready(function() {

        $("#btn-submit").click(function(){
            var userid = $.trim($("#userid").val());
            var username = $.trim($("#username").val());
            var role = $("#role").val();
            if(role == -1||username == ""||userid==""){
                layer.msg('有信息未输入，请检查!', {time: 2000});
            }else {
                var data1= {};
                data1.id = userid;
                data1.role = role;
                data1.username = username;
                $.ajax({
                    type:"POST",
                    url:"/user/save",  //接口
                    data:JSON.stringify(data1),
                    contentType: "application/json",
                    success:function(data){
                        if(data.result){
                            parent.layer.msg(data.msg, {time: 1000, icon:1});
                        }else{
                            parent.layer.msg(data.msg, {time: 1000, icon:2});
                        }
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    }
                });
            }
        });
        initSelector1();
    });
    function initSelector1(){
        var selector1=  $("#role");
        //freemarker遍历用法
        selector1.append("<option value='-1'>选择权限</option>");
            <#list role as t>
                var name="${t.rolename}";
                var id = "${t.id}";
                selector1.append("<option value='"+id+"'>"+name+"</option>");
            </#list>

    }
</script>
</body>

</html>